﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;

namespace PopShops.Entities
{
    public class Product
    {
        #region Public Properties

        [XmlAttribute("name")]
        public string Name { get; set; }
        [XmlAttribute("description")]
        public string Description { get; set; }
        [XmlAttribute("merchant_id")]
        public int MerchantID { get; set; }
        [XmlAttribute("large_image_url")]
        public string LargeImageUrl { get; set; }
        [XmlAttribute("medium_image_url")]
        public string MediumImageUrl { get; set; }
        [XmlAttribute("small_image_url")]
        public string SmallImageUrl { get; set; }
        [XmlAttribute("merchant_price")]
        public double MerchantPrice { get; set; }
        [XmlAttribute("retail_price")]
        public double RetailPrice { get; set; }

        //Version 2 Properties
        [XmlAttribute("id")]
        public long ProductID { get; set; }
        public Group ProductGroup { get; set; }

        #endregion

        #region Ctor

        public Product()
        { }

        
        //For V1
        public Product(string name, string description, int merchant_id, string large_image_url, string medium_image_url,
                        string small_image_url, double merchant_price, double retail_price)
        {
            this.Description = description;
            this.LargeImageUrl = large_image_url;
            this.MediumImageUrl = medium_image_url;
            this.MerchantID = merchant_id;
            this.MerchantPrice = merchant_price;
            this.Name = name;
            this.RetailPrice = retail_price;
            this.SmallImageUrl = small_image_url;
        }

        //For V2 with Product ID
        public Product(string name, string description, int merchant_id, string large_image_url, string medium_image_url,
                        string small_image_url, double merchant_price, double retail_price, long id)
        {
            this.Description = description;
            this.LargeImageUrl = large_image_url;
            this.MediumImageUrl = medium_image_url;
            this.MerchantID = merchant_id;
            this.MerchantPrice = merchant_price;
            this.Name = name;
            this.RetailPrice = retail_price;
            this.SmallImageUrl = small_image_url;

            this.ProductID = id;
        }

        //For V2 with Product Groups
        public Product(string name, string description, int merchant_id, string large_image_url, string medium_image_url,
                        string small_image_url, double merchant_price, double retail_price, long id, Group product_group)
        {
            this.Description = description;
            this.LargeImageUrl = large_image_url;
            this.MediumImageUrl = medium_image_url;
            this.MerchantID = merchant_id;
            this.MerchantPrice = merchant_price;
            this.Name = name;
            this.RetailPrice = retail_price;
            this.SmallImageUrl = small_image_url;

            this.ProductID = id;
            this.ProductGroup = product_group;
        }

        public Product(string name, string description, int merchant_id, string large_image_url, string medium_image_url,
            string small_image_url, double merchant_price, double retail_price, long id, long product_group_id, 
            int product_group_product_count, int product_group_merchant_count, double product_group_min_price, 
            double product_group_max_price)
        {
            this.Description = description;
            this.LargeImageUrl = large_image_url;
            this.MediumImageUrl = medium_image_url;
            this.MerchantID = merchant_id;
            this.MerchantPrice = merchant_price;
            this.Name = name;
            this.RetailPrice = retail_price;
            this.SmallImageUrl = small_image_url;

            this.ProductID = id;
            this.ProductGroup = new Group(product_group_id, product_group_product_count, product_group_merchant_count, product_group_min_price, product_group_max_price);
        }

        #endregion
    }

    [XmlRoot("products")]
    public class Products
    {
        public Products()
        { }

        [XmlAttribute("total_count")]
        public long TotalCount { get; set; }

        [XmlElement("product")]
        public List<Product> ProductCollection { get; set; }
    }

    public enum ProductSort
    {
        none,
        price_asc,
        price_desc
    }
}